// 统一的提示工具
const Toast = {
  // 成功提示
  success(title, duration = 2000) {
    wx.showToast({
      title,
      icon: 'success',
      duration
    });
  },

  // 错误提示
  error(title, duration = 2000) {
    wx.showToast({
      title,
      icon: 'none',
      duration
    });
  },

  // 加载中
  loading(title = '加载中...') {
    wx.showLoading({
      title,
      mask: true
    });
  },

  // 隐藏加载
  hideLoading() {
    wx.hideLoading();
  },

  // 确认弹窗
  confirm(content, title = '提示') {
    return new Promise((resolve, reject) => {
      wx.showModal({
        title,
        content,
        success(res) {
          if (res.confirm) {
            resolve(true);
          } else {
            reject(false);
          }
        },
        fail: reject
      });
    });
  }
};

module.exports = Toast;

